package grails.company



import grails.test.mixin.*
import grails.test.mixin.domain.DomainClassUnitTestMixin

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Employee)
@TestMixin(DomainClassUnitTestMixin)
class EmployeeTests {

    void testConstraints() {
        mockForConstraintsTests(Employee)
        def e = new Employee()
        assert !e.validate()
        assert "nullable" == e.errors['firstName']
        assert "nullable" == e.errors['lastName']
        assert "nullable" == e.errors['password']
        assert "nullable" == e.errors['emailAddress']
        assert "nullable" == e.errors['accountName']

        e = new Employee()
        e.firstName = 'Kevin'
        e.lastName = 'Spacey'
        e.password = 'pass'
        e.emailAddress = 'invalid'
        e.accountName = 'no'
        assert !e.validate()
        assert "email" == e.errors['emailAddress']
        assert "size" == e.errors['accountName']

        e = new Employee()
        e.firstName = 'Kevin'
        e.lastName = 'Spacey'
        e.password = 'pass'
        e.emailAddress = 'valid@ACME.com'
        e.accountName = 'gbush'
        assert !e.validate()
        // TODO Test domain objects aren't getting added with mockForConstraintsTests so unable to assert for uniqueness
        //assert "unique" == e.errors['accountName']

    }
}
